<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
    <title>芳小微宣</title>
    <!-- 引入 WeUI -->
    <link rel="stylesheet" href="http://res.wx.qq.com/open/libs/weui/0.4.0/weui.min.css">
    <link rel="stylesheet" href="css/dropload.css">
    <script src="js/jquery.min.js"> </script>
    <script src="js/dropload.min.js"></script>
    <script src="js/index.js"></script>
    <link rel="stylesheet" href="css/index.css">
    <style>
        .dropload-down {
            width: 100%;
            height: 50px;
        }
        .tabChange{
            width: 50%;
            height: 40px;
            line-height: 40px;
            float: left;
            text-align: center;
            background:#e5e5e5;
            font-size: 4.5rem;
            color: #848587;
        }
    </style>
</head>
<body>
<div class="tzggPage">
    <div class="weui_cells_title">班级视频</div>

    <div class="listAll">
        <div class="content">
            <!-- <div class="imgSin">
                 <a>
                     <div class="Photo_left"><img src="images/file.png"/></div>
                     <div class="Photo_right">
                         <span class="wordSin">的风范热的风范热的风范热的风范热的风范热</span>
                         <img class="imgCheck" src="images/noselect.png">
                         <div style="color: #9d9d9d">
                             <span style="width: 70%;display: inline-block; margin-left: 8px;">漳卅</span>
                             <span>2017/01/10</span>
                         </div>
                     </div>
                 </a>
             </div>-->
        </div>
    </div>

    <div class="btnChoose">
        <div id="returnIndex">
            <img src="images/return.png" style="width: 25px;padding-top: 8px;"><br>
            <span>返回</span>
        </div>
        <div>
            <img src="images/add.png" id="addNew" style="width: 66px;position: relative;top: -12px;">
        </div>
        <div id="delete">
            <img src="images/delete.png" style="width: 20px;padding-top: 8px;"><br>
            <span>删除</span>
        </div>
    </div>

    <div class="weui_dialog_alert" style="display: none;">
        <div class="weui_mask"></div>
        <div class="weui_dialog">
            <div class="weui_dialog_hd"> <strong class="weui_dialog_title">警告</strong>
            </div>
            <div class="weui_dialog_bd">弹窗内容，告知当前页面信息等</div>
            <div class="weui_dialog_ft">
                <a href="javascript:;" class="weui_btn_dialog primary">确定</a>
            </div>
        </div>
    </div>
</div>
    <script>
        $(function(){
            // 页数
            var page = 0;
            // 每页展示5个
            var size = 10;

            // dropload
            $('.listAll').dropload({
                scrollArea : window,
                loadDownFn : function(me){
                    page++;
                    // 拼接HTML
                    var result = '';
                    $.ajax({
                        type: 'GET',
                        url: path + '/api/weixin/getClassVideo?page='+page+'&size='+size+'&token='+window.localStorage.getItem("token"),
                        dataType: 'json',
                        success: function(data){
                            if(data.code == 501){
                                window.location.href = "login.html";
                                return;
                            }
                            var arrLen = data.videoInfoList.length;
                            if(arrLen > 0){

                                for(var i=0; i<arrLen; i++){
                                    var videoName = "";
                                   var index = data.videoInfoList[i].videoUrl.lastIndexOf("\/");

                                    videoName = data.videoInfoList[i].videoUrl.substring(index + 1, data.videoInfoList[i].videoUrl.length);

                                    result += '<div class="imgSin"> <a><div class="Photo_left"><img src="images/videoicon.png" style="width:40px;height:40px;padding-left: 5px;"/></div><div class="Photo_right"> <span class="wordSin" title="'+ data.videoInfoList[i].id +'">'+
                                            videoName +'</span>' +
                                            '<img class="imgCheck" src="images/noselect.png" title="'+ data.videoInfoList[i].id +'"> <div style="color: #9d9d9d">' +
                                            ' <span style="width: 70%;display: inline-block; margin-left: 8px;">'+ data.videoInfoList[i].className +'</span><span>'+
                                            data.videoInfoList[i].gmtCreate.substr(0,10) +'</span></div> </div></a></div>';
                                }
                            }else{
                                // 如果没有数据
                                // 锁定
                                me.lock();
                                // 无数据
                                me.noData();
                            }
                            // 插入数据到页面，放到最后面
                            $('.content').append(result);
                            // 每次数据插入，必须重置
                            me.resetload();
                        },
                        error: function(xhr, type){
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                }
            });
        });
        $.weui = {};
        $.weui.alert = function(options,sureEvent){
            options = $.extend({title: '提示', text: '提示内容'}, options);
            var $alert = $('.weui_dialog_alert');
            $alert.find('.weui_dialog_title').text(options.title);
            $alert.find('.weui_dialog_bd').text(options.text);
            $alert.on('touchend click', '.weui_btn_dialog', function(event){
                $alert.hide();
                if(sureEvent){
                    sureEvent();
                }
                //阻止事件冒泡
                // event.stopPropagation();
                return false;
            });
            $(".weui_mask").click(function(){
                $alert.hide();
            });
            $alert.show();
        };


        var deleList = [];
        $(".content").on('click','.imgCheck',function(){
            if($(this).attr("src").indexOf("selected")>0){
                $(this).attr("src","images/noselect.png");
            }else {
                $(this).attr("src","images/selected.png");
            }
        });

        $("#delete").click(function(){
            for(var i = 0;i< $(".imgCheck").length ; i++ ){
                if($(".imgCheck").eq(i).attr("src").indexOf("selected")>0){
                    deleList.push($(".imgCheck").eq(i).attr("title"));
                }
            }
            if(deleList.length == 0){
                $.weui.alert({text: "请选择要删除的数据！"});
            }else{
                $.weui.alert({text: "确定删除吗?"},function(){
                    //删除数据
                    $.ajax({
                        type : "POST",
                        url : path + "/api/weixin/deleteClassVideo",//?token=" + window.localStorage.getItem("token"),
                        data : {
                            "token" : window.localStorage.getItem("token"),
                            "ids" : JSON.stringify(deleList)
                        },
                        dataType : 'json',
                        success : function(msg) {
                            if(msg.code == 0){
                                window.location.href = "videoList.html";
                            }else if(msg.code == 501){
                                window.location.href = "login.html";
                            }
                        }
                    })
                });
            }
        });

        $("#returnIndex").click(function(){
            window.location.href = "index.html";
        });
        $("#addNew").click(function(){
            window.location.href = "classVideo.html";
        });

    </script>


</body>
</html>